package com.example.springbootdemo.proxy.dynamicproxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @author ：cici
 * @date ：Created in 2019/10/17 15:03
 */
public class StartProxy implements InvocationHandler {

    private Object target;

    public void setObject(Object target) {
        this.target = target;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("增强");
        Object result = method.invoke(target,args);
        return result;
    }

    public Object creatProxyedObj()
    {
        return Proxy.newProxyInstance(target.getClass().getClassLoader(), target.getClass().getInterfaces(), this);
    }

}
